package com.example.administrator.szb.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.bean.ColorBean;
import com.example.administrator.szb.bean.GWJGBean;
import com.example.administrator.szb.bean.IndexBean;
import com.example.administrator.szb.bean.StarBean;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.example.administrator.szb.fragments.fragment_forTab.home.adapter.JGadapter;
import com.example.administrator.szb.http.HttpUtil;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.DialogUtil;
import com.example.administrator.szb.util.GetJsonDataUtil;
import com.example.administrator.szb.util.ScreenExpressionUtils;
import com.example.administrator.szb.util.SharedPreferencesUtil;
import com.example.administrator.szb.util.SpannableStringUtil;
import com.example.administrator.szb.util.Toasts;
import com.example.administrator.szb.view.MyLinearLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.api.OnRefreshLoadmoreListener;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by D N on 2017/11/22.
 */

public class SearchYWActivity_new extends BaseActivity {
    @Bind(R.id.toolbar_fh_search_yw)
    ImageView toolbarFhSearchYw;
    @Bind(R.id.toolbar_title_search_yw)
    TextView toolbarTitleSearchYw;
    @Bind(R.id.image_search_yw)
    ImageView imageSearchYw;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.search_yw_checkbox_one)
    CheckBox searchYwCheckboxOne;
    @Bind(R.id.search_yw_one)
    MyLinearLayout searchYwOne;
    @Bind(R.id.search_yw_checkbox_two)
    CheckBox searchYwCheckboxTwo;
    @Bind(R.id.search_yw_two)
    MyLinearLayout searchYwTwo;
    @Bind(R.id.search_yw_checkbox_three)
    CheckBox searchYwCheckboxThree;
    @Bind(R.id.search_yw_three)
    MyLinearLayout searchYwThree;
    @Bind(R.id.search_yw_checkbox_four)
    CheckBox searchYwCheckboxFour;
    @Bind(R.id.search_yw_four)
    MyLinearLayout searchYwFour;
    @Bind(R.id.search_yw_zero)
    LinearLayout searchYwZero;
    @Bind(R.id.info_search)
    LinearLayout infoSearch;
    @Bind(R.id.search_yw_recyclerview)
    ListView searchYwRecyclerview;

    GWJGBean.DataBean.ConditListBean.NextBean nextBean_bx;//加入不限这itme;
    ArrayList<GWJGBean.DataBean.ConditListBean> mdata_next = new ArrayList<>();
    int id = 0;
    GWJGBean gwjgBean;
    BaseAdapter<GWJGBean.DataBean.ConditListBean.NextBean> adapter_next;

    int current_page = 1;
    int per_page = 12;
    @Bind(R.id.searchYW_new_swiperefreshlayout)
    SmartRefreshLayout searchYWNewSwiperefreshlayout;
    @Bind(R.id.search_yw_jt_one)
    CheckBox searchYwJtOne;
    @Bind(R.id.search_yw_jt_two)
    CheckBox searchYwJtTwo;
    @Bind(R.id.search_yw_jt_three)
    CheckBox searchYwJtThree;
    @Bind(R.id.search_yw_jt_four)
    CheckBox searchYwJtFour;

    private View footerview;//加载更多
    View error_head;

    JGadapter adapter;
    ArrayList<IndexBean.DataBean.HotCounBean> mdata = new ArrayList<>();

    HashMap<Integer, String> search_id = new HashMap<Integer, String>() {
        @Override
        public String toString() {
            String id = "";
            Set<Integer> keySet = search_id.keySet();
            //有了Set集合就可以获取其迭代器，取值
            Iterator<Integer> it = keySet.iterator();

            while (it.hasNext()) {
                Integer i = it.next();
                id = search_id.get(i) + "," + id;
            }
            return id;
        }
    };//搜索条件id
    private String one;
    private String two;
    private String three;
    private String four;
    private boolean isFirstEnter = true;
    private PopupWindow popupWindow;
    private TextView aaaaaa;
    String top_tipsStr = "";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_yw_activity);
        ButterKnife.bind(this);
        SampleApplicationLike.getActivitiesInstance().add(this);
        initView();
        footerview = LayoutInflater.from(this).inflate(R.layout.view_wd_footer, null);
        footerview.setVisibility(View.INVISIBLE);
        // requestGWData(0 + "");
    }
    private ImageView right_down;
    private void initView() {
        right_down = (ImageView) findViewById(R.id.right_down);
        aaaaaa = (TextView) findViewById(R.id.aaaaaa);
        top_tipsStr=aaaaaa.getText().toString();
        aaaaaa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                right_down.setVisibility(View.VISIBLE);
                aaaaaa.setSingleLine(true);
                aaaaaa.setText(top_tipsStr);
            }
        });
        right_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                right_down.setVisibility(View.GONE);
                aaaaaa.setSingleLine(false);
                SpannableStringUtil stringUtil = new SpannableStringUtil(aaaaaa);
                stringUtil.addText(top_tipsStr);
                stringUtil.addTextWithImg("这是图片",R.mipmap.circle_up,null,new int[]{40,40});
                aaaaaa.setText(stringUtil.getText());

                aaaaaa.setText(stringUtil.getText());

            }
        });
        toolbarTitleSearchYw.setText(getIntent().getStringExtra("title"));
        id = getIntent().getIntExtra("id", -1);
        initRefresh();
    }

    private void initRefresh() {
//        searchYWNewSwiperefreshlayout.setColorSchemeResources(R.color.zhutise);
////        searchYWNewSwiperefreshlayout.post(new Runnable() {
////            @Override
////            public void run() {
////                current_page = 1;
////                searchYWNewSwiperefreshlayout.setRefreshing(true);
////                requestGWData(search_id.toString());
////            }
////        });
//
//        searchYWNewSwiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                current_page = 1;
//                searchYWNewSwiperefreshlayout.setRefreshing(false);
//                //requestGWData(search_id.toString());
//            }
//        });

        if (isFirstEnter) {
            searchYWNewSwiperefreshlayout.autoRefresh();
        }
        searchYWNewSwiperefreshlayout.setEnableLoadMore(true);//是否启用上拉加载功能
        searchYWNewSwiperefreshlayout.setEnableLoadMoreWhenContentNotFull(true);//是否在列表不满一页时候开启上拉加载功能


        searchYWNewSwiperefreshlayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                //refreshlayout.setLoadmoreFinished(false);//恢复上拉状态
                // Toasts.show(getActivity(), "加载更多啊", Toast.LENGTH_SHORT);
                requestGWData(search_id.toString(), 1);
            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                current_page = 1;
                requestGWData(search_id.toString(), 0);
                //refreshlayout.finishRefresh();
            }
        });
    }


    private void requestGWData(final String arr, final int isRefreshOrMore) {
        HashMap<String, String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam());
        map.put("id", id + "");
        map.put("arr", "" + arr);
        map.put("current_page", current_page + "");
        map.put("per_page", per_page + "");
        String url = URLAddress.URLBASE + URLAddress.URL_GWJG;
        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, GWJGBean.class, URLAddress.URLBASE + URLAddress.URL_GWJG, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                gwjgBean = (GWJGBean) response;
                findViewById(R.id.search_new_errot_net_include).setVisibility(View.GONE);
                try {
                    if (gwjgBean.getResult() == 1 && current_page == 1 && isRefreshOrMore == 0) {
                        searchYWNewSwiperefreshlayout.finishRefresh();
                        current_page = current_page + 1;
                        mdata.clear();
                        mdata.addAll(gwjgBean.getData().getDataList());
                        if (isFirstEnter) {//只在开始的时候初始化
                            searchYwZero.setVisibility(View.VISIBLE);
                            isFirstEnter = false;
                            mdata_next.addAll(gwjgBean.getData().getConditList());
                            //为弹框加入不限这个选项
                            for (int i = 0; i < mdata_next.size(); i++) {
                                nextBean_bx = new GWJGBean.DataBean.ConditListBean.NextBean();
                                nextBean_bx.setIsChoose(1);
                                nextBean_bx.setShowtitle("不限");
                                nextBean_bx.setId(0);
                                mdata_next.get(i).getNext().add(0, nextBean_bx);
                            }

                            initSearchTitle();
                        }


                        footerview.setVisibility(View.INVISIBLE);
                    } else if (isRefreshOrMore == 1) {
                        searchYWNewSwiperefreshlayout.finishLoadmore();
                        current_page = current_page + 1;
                        mdata.addAll(gwjgBean.getData().getDataList());


                    }
                    initRecyclerview();
                } catch (Exception e) {

                    DialogUtil.showToast(SearchYWActivity_new.this, "发生异常！");
                    footerview.setVisibility(View.INVISIBLE);
                    searchYWNewSwiperefreshlayout.finishRefresh();
                    findViewById(R.id.search_new_errot_net_include).setVisibility(View.VISIBLE);
                    findViewById(R.id.search_new_errot_net_include).findViewById(R.id.home_fragment_button_djcs_error).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            requestGWData(search_id.toString(), 0);
                        }
                    });
                }


            }

        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                footerview.setVisibility(View.INVISIBLE);
                searchYWNewSwiperefreshlayout.finishRefresh();
                findViewById(R.id.search_new_errot_net_include).setVisibility(View.VISIBLE);
                findViewById(R.id.search_new_errot_net_include).findViewById(R.id.home_fragment_button_djcs_error).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestGWData(search_id.toString(), 0);
                    }
                });
                error.toString();
            }
        });
    }

    /**
     * 初始化搜索title
     */
    private void initSearchTitle() {
        switch (gwjgBean.getData().getConditList().size()) {
            case 1:
                break;
            case 2:
                break;
            case 3:
                searchYwFour.setVisibility(View.GONE);
                break;
            case 4:
                break;

        }


        one = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(0).getShowtitle()) ? gwjgBean.getData().getConditList().get(0).getTitle() : gwjgBean.getData().getConditList().get(0).getShowtitle();
        two = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(1).getShowtitle()) ? gwjgBean.getData().getConditList().get(1).getTitle() : gwjgBean.getData().getConditList().get(1).getShowtitle();
        three = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(2).getShowtitle()) ? gwjgBean.getData().getConditList().get(2).getTitle() : gwjgBean.getData().getConditList().get(2).getShowtitle();

        four = "";
        try {
            four = TextUtils.isEmpty(gwjgBean.getData().getConditList().get(3).getShowtitle()) ? gwjgBean.getData().getConditList().get(3).getTitle() : gwjgBean.getData().getConditList().get(3).getShowtitle();

        } catch (Exception e) {

        }


        searchYwCheckboxOne.setText(one);
        searchYwCheckboxTwo.setText(two);
        searchYwCheckboxThree.setText(three);
        searchYwCheckboxFour.setText(four);


    }

    private void initRecyclerview() {



        searchYwRecyclerview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(SearchYWActivity_new.this, JGXQActivity.class);
                intent.putExtra("id", mdata.get(position).getId());
                intent.putExtra("id_type", id);
                startActivity(intent);
            }
        });

        if (mdata.size() == 0) {

            String info = "未搜索到相关机构";
            Toasts.show(this,""+info);
        }
        if (adapter==null){
            adapter = new JGadapter(this,mdata);
            searchYwRecyclerview.setAdapter(adapter);
        }else {
            adapter.notifyDataSetChanged();
        }





    }


    private void initItem(BaseAdapter.BaseViewHolder holder, GWJGBean.DataBean.DataListBean dataBean, int position) {
        if (!TextUtils.isEmpty(dataBean.getZhenshi_img())) {
            Glide.with(this).load(dataBean.getZhenshi_img()).into((ImageView) (holder).getView(R.id.imageView20));
        }
        ((TextView) holder.getView(R.id.textView49)).setText(dataBean.getCompany() + "-" + dataBean.getName());
        if (dataBean.getCompany() == null) {
            ((TextView) holder.getView(R.id.textView50)).setVisibility(View.INVISIBLE);
        } else {
            ((TextView) holder.getView(R.id.textView50)).setVisibility(View.INVISIBLE);
            //((TextView)holder.getView(R.id.textView50)).setText(dataBean.getCompany());
        }
        if (dataBean.getCity() == null) {
            ((TextView) holder.getView(R.id.textView51)).setVisibility(View.INVISIBLE);
        } else {
            ((TextView) holder.getView(R.id.textView51)).setText((String) dataBean.getCity());
        }


        /**
         * 显示业务标签
         */

        showYW(dataBean, holder, position);

        /**
         * 显示星星
         */
        showStar(dataBean, holder);
    }

    private void showStar(final GWJGBean.DataBean.DataListBean dataBean, BaseAdapter.BaseViewHolder holder) {
        final ArrayList<StarBean> mdata = new ArrayList<>();
        RecyclerView recyclerView = ((RecyclerView) holder.getView(R.id.zdyh_recyclerview_star));
        recyclerView.setLayoutManager(new GridLayoutManager(this, 5));
        for (int i = 0; i < 5; i++) {
            StarBean b = new StarBean();
            mdata.add(b);
        }
        BaseAdapter<StarBean> adapter = new BaseAdapter<StarBean>(SearchYWActivity_new.this, mdata) {
            @Override
            public void convert(int position, BaseViewHolder holder, StarBean starBean) {
                ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.star_hui);
                if (dataBean.getEvaluate() / 2 > position) {
                    ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.start);
                }
                if (position == dataBean.getEvaluate() / 2 + dataBean.getEvaluate() % 2 - 1 && dataBean.getEvaluate() % 2 != 0) {
                    ((ImageView) holder.getView(R.id.view_zdyh_star)).setImageResource(R.drawable.star_half);
                }
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_zdyh_star;
            }
        };
        recyclerView.setAdapter(adapter);
    }

    private void showYW(GWJGBean.DataBean.DataListBean dataBean, BaseAdapter.BaseViewHolder holder, final int position) {

        RecyclerView recyclerView = ((RecyclerView) holder.getView(R.id.zdyh_recyclerview_ywbq));
        recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        /**
         * 截获事件，业务标签的recyclerview 会劫持事件，如果不加上点击失效
         */
        recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {//此处是点击按下时才执行跳转动作
                    // Toasts.show(mActivity, "....", Toast.LENGTH_SHORT);
                    Intent intent = new Intent(SearchYWActivity_new.this, JGXQActivity.class);
                    intent.putExtra("id", mdata.get(position).getId());
                    intent.putExtra("id_type", id);
                    startActivity(intent);

                    //startActivity(new Intent(ProfileEdit.this, EditDepartment.class));
                }
                return false;
            }
        });

        BaseAdapter<GWJGBean.DataBean.DataListBean.BusinessIdBean> adapter = new BaseAdapter<GWJGBean.DataBean.DataListBean.BusinessIdBean>(this, dataBean.getBusiness_id(), 4) {
            @Override
            public void convert(int position, BaseViewHolder holder, GWJGBean.DataBean.DataListBean.BusinessIdBean businessBean) {
                GradientDrawable drawable;
                ((TextView) holder.getView(R.id.view_jgxq_text)).setText(businessBean.getTitle());
                try {
                    Class<?> c = null;
                    c = Class.forName("bean.ColorBean$DataBean");
                    ColorBean.DataBean obj = (ColorBean.DataBean) c.newInstance();
                    //第一个参数写的是方法名,第二个\第三个\...写的是方法参数列表中参数的类型
                    Method method = c.getMethod("get_$" + businessBean.getId());
                    ColorBean colorbean = (ColorBean) SharedPreferencesUtil.getData(SearchYWActivity_new.this, "yw_color");
                    String str2 = (String) method.invoke(colorbean.getData());


                    drawable = (GradientDrawable) ((TextView) holder.getView(R.id.view_jgxq_text)).getBackground();
                    drawable.setColor(Color.parseColor(str2));
                } catch (Exception e) {

                }


            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_jgxq_item;
            }
        };
        recyclerView.setAdapter(adapter);
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @OnClick({R.id.image_search_yw, R.id.toolbar_fh_search_yw, R.id.search_yw_one, R.id.search_yw_two, R.id.search_yw_three, R.id.search_yw_four})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.toolbar_fh_search_yw:
                finish();
                break;

            case R.id.image_search_yw:
                startActivity(new Intent(this, SearchActivity.class));
                break;
            case R.id.search_yw_one:
                //searchYwOne.setStatu(true);
                showPopu(0);
                break;
            case R.id.search_yw_two:
                showPopu(1);
                break;
            case R.id.search_yw_three:
                showPopu(2);
                break;
            case R.id.search_yw_four:
                showPopu(3);
                break;
        }
    }


    /**
     * 初始化popupwindow弹出框
     */
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void showPopupwindowSX(final int data_positon, int margin, int view_layout_id, int rootview_layout_id, CallbackPopuwindow callback) {
        View popwindow_view = LayoutInflater.from(this).inflate(view_layout_id, null);
        View rootview = LayoutInflater.from(this).inflate(rootview_layout_id, null);
        callback.doSomeThing(popwindow_view);
        popupWindow = new PopupWindow(popwindow_view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

        popupWindow.setTouchable(true);

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (data_positon) {
                    case 0:
                        searchYwJtOne.setChecked(false);
                        break;
                    case 1:
                        searchYwJtTwo.setChecked(false);
                        break;
                    case 2:
                        searchYwJtThree.setChecked(false);
                        break;
                    case 3:
                        searchYwJtFour.setChecked(false);
                        break;
                }

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });

        //如果不设置PopupWindow的背景，无论是点击外部区域还是Back键都无法dismiss弹框
        //我觉得这里是API的一个bug
        popupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.white));

        // 设置好参数之后再show
        popupWindow.showAtLocation(rootview, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, margin);
        //显示PopupWindow

    }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void showPopu(final int data_positon) {
        showPopupwindowSX(data_positon, ScreenExpressionUtils.dip2px(this, 113), R.layout.view_popuwindow_base_tjzl, R.layout.search_yw_activity, new CallbackPopuwindow() {
            @Override
            public void doSomeThing(View view) {
                RecyclerView recyclerView = view.findViewById(R.id.view_popuwindow_recycler_base_tjzl);
                recyclerView.setLayoutManager(new LinearLayoutManager(SearchYWActivity_new.this));
                //initAdapter_next();
                adapter_next = new BaseAdapter<GWJGBean.DataBean.ConditListBean.NextBean>(SearchYWActivity_new.this, mdata_next.get(data_positon).getNext()) {
                    @Override
                    public void convert(int position, BaseViewHolder holder, GWJGBean.DataBean.ConditListBean.NextBean nextBean) {

                        if (nextBean.getIsChoose() == 1) {
                            ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setTextColor(getResources().getColor(R.color.tab_choose));
                        } else {
                            ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setTextColor(getResources().getColor(R.color.toolbar_home));
                        }

                        if (TextUtils.isEmpty(nextBean.getShowtitle().toString())) {
                            ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setText(nextBean.getTitle());
                        } else {
                            ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setText(nextBean.getShowtitle().toString());
                        }
                    }

                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.view_popuwindow_base_tjzl_item;
                    }
                };
                recyclerView.setAdapter(adapter_next);


                adapter_next.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        current_page = 1;
                        for (int i = 0; i < mdata_next.get(data_positon).getNext().size(); i++) {
                            mdata_next.get(data_positon).getNext().get(i).setIsChoose(0);
                        }

                        mdata_next.get(data_positon).getNext().get(position).setIsChoose(1);


                        search_id.remove(data_positon);

                        if (mdata_next.get(data_positon).getNext().get(position).getUnlimited() == 1) {
                            search_id.put(data_positon, 0 + "");
                        } else {
                            search_id.put(data_positon, mdata_next.get(data_positon).getNext().get(position).getId() + "");
                        }


                        requestGWData(search_id.toString(), 0);


                        /**
                         * 改变标题颜色
                         */
                        if (mdata_next.get(data_positon).getNext().get(position).getShowtitle().equals("不限")) {
                            switch (data_positon) {
                                case 0:
                                    searchYwOne.setStatu(false);
                                    break;
                                case 1:
                                    searchYwTwo.setStatu(false);
                                    break;
                                case 2:
                                    searchYwThree.setStatu(false);
                                    break;
                                case 3:
                                    searchYwFour.setStatu(false);
                                    break;
                            }

                        } else {
                            switch (data_positon) {
                                case 0:
                                    searchYwJtOne.setChecked(false);
                                    break;
                                case 1:
                                    //searchYwTwo.setStatu(false);
                                    break;
                                case 2:
                                    //searchYwThree.setStatu(false);
                                    break;
                                case 3:
                                    //searchYwFour.setStatu(false);
                                    break;
                            }
                        }
                        //改变标题内容
                        switch (data_positon) {
                            case 0:
                                //searchYwOne.setStatu(false);
                                searchYwCheckboxOne.setText(mdata_next.get(data_positon).getNext().get(position).getShowtitle().toString());
                                break;
                            case 1:
                                //searchYwTwo.setStatu(false);
                                searchYwCheckboxTwo.setText(mdata_next.get(data_positon).getNext().get(position).getShowtitle().toString());
                                break;
                            case 2:
                                //searchYwThree.setStatu(false);
                                searchYwCheckboxThree.setText(mdata_next.get(data_positon).getNext().get(position).getShowtitle().toString());
                                break;
                            case 3:
                                //searchYwFour.setStatu(false);
                                searchYwCheckboxFour.setText(mdata_next.get(data_positon).getNext().get(position).getShowtitle().toString());
                                break;
                        }

                        /**
                         * 改变标题颜色
                         */
                        if (mdata_next.get(data_positon).getNext().get(position).getShowtitle().equals("不限")) {
                            switch (data_positon) {
                                case 0:
                                    //searchYwOne.setStatu(false);
                                    searchYwCheckboxOne.setText(one);
                                    break;
                                case 1:
                                    //searchYwTwo.setStatu(false);
                                    searchYwCheckboxTwo.setText(two);
                                    break;
                                case 2:
                                    //searchYwThree.setStatu(false);
                                    searchYwCheckboxThree.setText(three);
                                    break;
                                case 3:
                                    //searchYwFour.setStatu(false);
                                    searchYwCheckboxFour.setText(four);
                                    break;
                            }
                        }

                        popupWindow.dismiss();


                    }
                });
            }
        });
    }


}
